package com.yoomiito.app.adapter.home.reommend;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.yoomiito.app.R;

/**
 * 首页----小标题
 */
public class HomeTitleAdapter extends DelegateAdapter.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private LayoutHelper mLayoutHelper;
    private String[] titles = {"热门活动","为您推荐","限时秒杀"};
    private int pos;
    public HomeTitleAdapter(Context context, LayoutHelper layoutHelper, int pos) {
        mContext = context;
        mLayoutHelper = layoutHelper;
        this.pos = pos;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.home_item_text,parent,false);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
        itemViewHolder.tv.setText(titles[pos]);
    }

    @Override
    public int getItemViewType(int position) {
        return 4;
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    private class ItemViewHolder extends RecyclerView.ViewHolder{

        private TextView tv;

        public ItemViewHolder(View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv_text);
        }
    }
}
